package com.you.place.dal.dao;

import java.util.HashMap;
import java.util.Map;

import com.you.common.ibatis.AbstractDAO;
import com.you.common.ibatis.data.DataList;
import com.you.common.ibatis.param.QueryParam;
import com.you.place.dal.dao.dataobject.RateDO;

public class RateDAO extends AbstractDAO {

    public RateDO find(Long memberId, Long placeId) {
        Map<String, Long> param = new HashMap<String, Long>();
        param.put("memberId", memberId);
        param.put("placeId", placeId);
        return (RateDO) super.getSqlMapClientTemplate().queryForObject("MS-SELECT-RATE-BY-MEMBERID-PLACE-ID", param);
    }

    public Long create(RateDO RateDO) {
        return (Long) getSqlMapClientTemplate().insert("MS-INSERT-RATE", RateDO);
    }

    public Integer delete(Long memberId, Long placeId) {
        Map<String, Long> param = new HashMap<String, Long>();
        param.put("memberId", memberId);
        param.put("placeId", placeId);
        return (Integer) getSqlMapClientTemplate().delete("MS-DELETE-RATE", param);
    }

    public DataList queryByMemberId(int pageNo, int pageSize, Long memberId) {
        QueryParam<String, Long> queryParam = new QueryParam<String, Long>();
        queryParam.setPageNo(pageNo);
        queryParam.setPageSize(pageSize);
        queryParam.put("memberId", memberId);
        return super.getSqlMapClientTemplate().pagedQuery(queryParam, "MS-SELECT-RATE-BY-MEMBER-ID");
    }

    public DataList queryByPlaceId(int pageNo, int pageSize, Long placeId) {
        QueryParam<String, Long> queryParam = new QueryParam<String, Long>();
        queryParam.setPageNo(pageNo);
        queryParam.setPageSize(pageSize);
        queryParam.put("placeId", placeId);
        return super.getSqlMapClientTemplate().pagedQuery(queryParam, "MS-SELECT-RATE-BY-PLACE-ID");
    }

    public Long count(Long memberId) {
        return (Long) getSqlMapClientTemplate().queryForObject("MS-COUNT-RATE-BY-MEMBER-ID", memberId);
    }
}
